package com.next

class SecurityProfileItem
{
    String controllerName
    String actionName
    String name
    String description
    Boolean active = true

    User createBy
    User modifyBy

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    static belongsTo = [profile: SecurityProfile]

    static constraints = {
        controllerName maxSize: 256
        actionName maxSize: 256, unique: ['controllerName']
        name maxSize: 64, unique: ['profile']
        description maxSize: 512, nullable: true, blank: true

        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    static mapping = {
        cache true
        sort 'controllerName', 'actionName'
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
